#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/11/8 16:39
# @Author : 闫峰
# @File    : template_id_t_walmart_listing.py
import datetime

import requests

from common.setting import ensure_path_sep
from utils.mysqlUtils.db_pool import Database
import os
import threading
import time
from common.setting import ensure_path_sep
from utils.logging_tool.log_control import LogHandler
from utils.mysqlUtils.db_pool import Database

current_path = os.path.abspath(__file__)
current_dir = os.path.dirname(current_path)
path_list = current_path.split("\\")
dis_path = "\\".join(path_list[-2:-1])


def remove_file(info_path):
    if os.path.exists(info_path):
        os.remove(info_path)
    else:
        print(f"{info_path} 不存在")


info_path = ensure_path_sep(f"\\logs\\info-{dis_path}{time.time()}")
error_path = ensure_path_sep(f"\\logs\\\error-{dis_path}{time.time()}.log")
warning_path = ensure_path_sep(f"\\logs\\warning-{dis_path}{time.time()}.log")
remove_file(info_path)
remove_file(error_path)
remove_file(warning_path)
INFO = LogHandler(info_path, level='info')
ERROR = LogHandler(error_path, level='error')
WARNING = LogHandler(warning_path, level='warning')

class Test:


    def test(self):
        db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "test_jdw_database")
        get_data = """
        SELECT source_id,sku,item_id,template_id 
        FROM test_zhcxkj_center_datasync_comprehensive.t_walmart_sku_shipping_template 
        WHERE update_time >= DATE_SUB(NOW(),INTERVAL 1 DAY)
        """
        data = db.fetch_all_tuple(get_data,())
        for data1 in data:
            get_template_id = """
            		SELECT id,template_id FROM test_zhcxkj_center_listing_comprehensive.t_walmart_listing 
		WHERE source_id=%s
			AND source_sku=%s
			AND item_id=%s
            """
            res = db.fetch_all_tuple(get_template_id, (data1[0],data1[1],data1[2]))
            if len(res):
                if res[0][0] == data1[3]:
                    pass
                else:
                    print(f"{data1}template_id同步错误")
            else:
                print(f"在t_walmart_listing表未查询到数据{data1}")

if __name__ == '__main__':
    Test().test()
